\hypertarget{md_README_autotoc_md1}{}\doxysection{A\+B\+O\+U\+T L\+I\+B\+S\+C\+HC}\label{md_README_autotoc_md1}
libschc is a C implementation of the Static Context Header Compression, drafted by the I\+E\+TF. It is a header compression technique, used in Low Power Wide Area Networks in order to enable tiny low-\/power microcontrollers to have an end-\/to-\/end I\+Pv6 connection. This repository contains both the compression aswell as the fragmentation mechanism. For further information related to S\+C\+HC, see \href{https://datatracker.ietf.org/doc/draft-ietf-lpwan-ipv6-static-context-hc/}{\texttt{ https\+://datatracker.\+ietf.\+org/doc/draft-\/ietf-\/lpwan-\/ipv6-\/static-\/context-\/hc/}}.\hypertarget{md_README_autotoc_md2}{}\doxysection{L\+I\+M\+I\+T\+A\+T\+I\+O\+NS}\label{md_README_autotoc_md2}
As this implementation is work in progress, there are some limitations you should keep in mind. The library has been designed in such a way, that it can be used on top of a constrained device, as well as on a more powerful server side device. As a consequence, memory allocation and memory intensive calculations are avoided. I tended to use fixed point arithmetic for 8-\/bit mircoprocessors, however some optimizations are possible.

The {\ttfamily schc-\/config.\+h} file contains a definition for dynamic memory allocation, used by fragmenter.

The current implementation is based on draft-\/ietf-\/lpwan-\/ipv6-\/static-\/context-\/hc-\/18 (\href{https://datatracker.ietf.org/doc/draft-ietf-lpwan-ipv6-static-context-hc/18/}{\texttt{ https\+://datatracker.\+ietf.\+org/doc/draft-\/ietf-\/lpwan-\/ipv6-\/static-\/context-\/hc/18/}}), some naming conventions are therefore not in line with the current specification.\hypertarget{md_README_autotoc_md3}{}\doxysection{D\+O\+C\+U\+M\+E\+N\+T\+A\+T\+I\+ON}\label{md_README_autotoc_md3}
\hypertarget{md_README_autotoc_md4}{}\doxysubsection{Configuration}\label{md_README_autotoc_md4}
First copy the configuration file 
\begin{DoxyCode}{0}
\DoxyCodeLine{mv schc\_config\_example.h schc\_config.h}
\end{DoxyCode}
 and edit the definitions according to your platform.\hypertarget{md_README_autotoc_md5}{}\doxysubsection{Rules}\label{md_README_autotoc_md5}
As the rules tend to consume a large part of memory, and

Currently, I only have been working with rules for a single device. However, as the server application will have to keep track of multiple devices, this should be implemented in a decoupled way. The rules are implemented in a layered fashion and should be combined with a rule map to use different layers in a single ID. This map could then be reused for different devices.

In {\ttfamily \mbox{\hyperlink{rules_8h}{rules.\+h}}}, several rules can be defined 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{struct }\mbox{\hyperlink{structschc__rule}{schc\_rule}} \{}
\DoxyCodeLine{    uint16\_t \mbox{\hyperlink{structschc__rule_afd8204c9d5c8d9262ce77ff417322b3c}{rule\_id}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__rule_a514775672b0343784cda603a5ec4e61c}{up}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__rule_aead6af025477ce0b7c180b9df5091057}{down}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__rule_af5f20076e164f0bbeaf3f2fbbab1ee78}{length}};}
\DoxyCodeLine{    \textcolor{keyword}{struct }\mbox{\hyperlink{structschc__field}{schc\_field}} \mbox{\hyperlink{structschc__rule_a8f5dabb53d4bd4cfa409a2b56faef7d0}{content}}[\mbox{\hyperlink{schc__config_8h_af1690024e8fe24a690d86ec4dd5d3bb6}{COAP\_FIELDS}}];}
\DoxyCodeLine{\};}
\end{DoxyCode}
 Where the number of fields with Field Direction UP and D\+O\+WN are set and the total number of fields in the rule The rule is therefore constructed of different {\ttfamily \mbox{\hyperlink{structschc__field}{schc\+\_\+field}}}\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{struct }\mbox{\hyperlink{structschc__field}{schc\_field}} \{}
\DoxyCodeLine{    \textcolor{keywordtype}{char} \mbox{\hyperlink{structschc__field_a95686cf98fe8ea0e3e613fc7b3543a9c}{field}}[32];}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__field_a29edf1bbed3c31adec3a364ab55389ed}{msb\_length}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__field_a935adff07534f10568676ffa884ea4aa}{field\_length}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__field_af44027e5add508a163aef5a0898bbb15}{field\_pos}};}
\DoxyCodeLine{    \mbox{\hyperlink{config_8h_a99f26e6ee9fcd62f75203b5402df8098}{direction}} \mbox{\hyperlink{structschc__field_a23f0e54fa507136cff38e313b3f064cb}{dir}};}
\DoxyCodeLine{    \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} \mbox{\hyperlink{structschc__field_ac630b87f129d988ad5d18d2f22375354}{target\_value}}[\mbox{\hyperlink{schc__config_8h_aa6420ecddb30151dd25bc1a2da3aacd1}{MAX\_COAP\_FIELD\_LENGTH}}];}
\DoxyCodeLine{    uint8\_t (*\mbox{\hyperlink{structschc__field_ae2dd6faff6388e1b0b4ecd973ebbd4af}{MO}})(\textcolor{keyword}{struct }\mbox{\hyperlink{structschc__field}{schc\_field}}* target\_field, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char}* field\_value);}
\DoxyCodeLine{    \mbox{\hyperlink{config_8h_a3e43f38d5254d1e3bbf1d0955eb98ce4}{CDA}} \mbox{\hyperlink{structschc__field_a53b37bd9de93614e76640174cffa11fa}{action}};}
\DoxyCodeLine{\};}
\end{DoxyCode}

\begin{DoxyItemize}
\item {\ttfamily field} holds a string of the field name (i.\+e. the human-\/readability of the rules).
\item the {\ttfamily msb\+\_\+length} is used in combination with the Matching Operator {\ttfamily M\+SB}, but should be removed in coming releases.
\item the {\ttfamily field\+\_\+length} indicates the length of {\bfseries{bytes}}, but should be bits in coming releases. Field Position is only used for headers where multiple fields can exist for the same entry (e.\+g. Co\+AP uri-\/path).
\item {\ttfamily dir} indicates the direction ({\ttfamily UP}, {\ttfamily D\+O\+WN} or {\ttfamily BI}) and will have an impact on how the rules behave while compressing/decompressing. Depending on the {\ttfamily \#define S\+E\+R\+V\+ER} in {\ttfamily \mbox{\hyperlink{schc__config_8h}{schc\+\_\+config.\+h}}}, the source and destination in the {\ttfamily decompress\+\_\+ipv6\+\_\+rule} and {\ttfamily generate\+\_\+ip\+\_\+header\+\_\+fields} will be swapped, to ensure a single rule for server and end device.
\item {\ttfamily target\+\_\+value} holds a {\ttfamily char} array in order to support larger values. The downside of this approach is the {\ttfamily M\+A\+X\+\_\+\+C\+O\+A\+P\+\_\+\+F\+I\+E\+L\+D\+\_\+\+L\+E\+N\+G\+TH} definition, which should be set to the largest defined Target Value in order to save as much memory as possible.
\item the {\ttfamily MO} is a pointer to the Matching Operator functions (defined in {\ttfamily \mbox{\hyperlink{config_8h}{config.\+h}}})
\item {\ttfamily C\+DA} contains the Compression/\+Decompression action ({\ttfamily enum} in {\ttfamily \mbox{\hyperlink{config_8h}{config.\+h}}})
\end{DoxyItemize}

Once all the rules are set up for a device, these can be saved and added to the device definition 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{struct }\mbox{\hyperlink{structschc__device}{schc\_device}} \{}
\DoxyCodeLine{    uint32\_t \mbox{\hyperlink{structschc__device_a5f22593142303b2722a0b9fb4167949e}{id}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__device_a5083555c2c2ccf7596ff712a5f553164}{ipv6\_count}};}
\DoxyCodeLine{    \textcolor{keyword}{const} \textcolor{keyword}{struct }\mbox{\hyperlink{structschc__rule}{schc\_rule}}* \mbox{\hyperlink{structschc__device_a48b4d7fc260918b615608790b7913fcc}{ipv6\_rules}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__device_a15834e0951fb90004fc75760cc43109a}{udp\_count}};}
\DoxyCodeLine{    \textcolor{keyword}{const} \textcolor{keyword}{struct }\mbox{\hyperlink{structschc__rule}{schc\_rule}}* \mbox{\hyperlink{structschc__device_a29183298f7685ea9e6e88e0f72902b9c}{udp\_rules}};}
\DoxyCodeLine{    uint8\_t \mbox{\hyperlink{structschc__device_ad2762cbab006c80cc2ffebe131e327ea}{coap\_count}};}
\DoxyCodeLine{    \textcolor{keyword}{const} \textcolor{keyword}{struct }\mbox{\hyperlink{structschc__rule}{schc\_rule}}* \mbox{\hyperlink{structschc__device_a2a3b02f0e0c66aea96fb08a64fa8b77f}{coap\_rules}};}
\DoxyCodeLine{\};}
\end{DoxyCode}
 This is all done very statically and needs further enhancements.

The {\ttfamily \mbox{\hyperlink{rules_8h}{rules.\+h}}} file should contain enough information to try out different settings.\hypertarget{md_README_autotoc_md6}{}\doxysubsection{Compressor}\label{md_README_autotoc_md6}
The compressor performs all actions to compress the given protocol headers. First, the compressesor should be initialized with the node it\textquotesingle{}s source IP address (8 bit array)\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{uint8\_t \mbox{\hyperlink{compressor_8c_a4fd03f3acd56b4bf55fc4c8e48567ab7}{schc\_compressor\_init}}(uint8\_t src[16]);}
\end{DoxyCode}


In order to compress a Co\+A\+P/\+U\+D\+P/\+IP packet, the following function can be called. This requires a buffer ({\ttfamily uint8\+\_\+t $\ast$buf}) to which the compressed packet may be returned. 
\begin{DoxyCode}{0}
\DoxyCodeLine{int16\_t \mbox{\hyperlink{compressor_8c_abd42f4bd7b7fdd8ea7b4c3504720a0ea}{schc\_compress}}(\textcolor{keyword}{const} uint8\_t *data, uint8\_t* buf, uint16\_t total\_length);}
\end{DoxyCode}


The reverse can be done by calling\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{uint16\_t \mbox{\hyperlink{compressor_8c_a48ebb52c79106c2a7658a513c2a65463}{schc\_construct\_header}}(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char}* data, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *header,}
\DoxyCodeLine{    uint32\_t device\_id, uint16\_t total\_length, uint8\_t *header\_offset);}
\end{DoxyCode}
 This requires a buffer to which the decompressed headers can be returned ({\ttfamily unsigned char $\ast$header}), a pointer to the complete original data packet ({\ttfamily unsigned char $\ast$data}), the device id and total length and finally a pointer to an integer ({\ttfamily uint8\+\_\+t $\ast$header\+\_\+offset}), which will return the compressed header size (i.\+e. the position in the buffer where the actual data starts). The function will return the decompressed header length.

Once the decompressed packet has been constructed, the U\+DP length and checksum may be calculated (this is still an open issue, as these functions should be called from the {\ttfamily construct\+\_\+header} function itself). 
\begin{DoxyCode}{0}
\DoxyCodeLine{uint16\_t \mbox{\hyperlink{compressor_8c_a650a861e13b9cb68043df5319d83b92d}{compute\_length}}(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *data, uint16\_t data\_len);}
\DoxyCodeLine{uint16\_t \mbox{\hyperlink{compressor_8c_a89368d1a9e14855697684aa89b0f1aac}{compute\_checksum}}(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *data);}
\end{DoxyCode}


The result should be a complete decompressed packet.\hypertarget{md_README_autotoc_md7}{}\doxysubsection{Fragmenter}\label{md_README_autotoc_md7}
The fragmenter and compressor are decoupled and require seperate initialization. 
\begin{DoxyCode}{0}
\DoxyCodeLine{int8\_t \mbox{\hyperlink{fragmenter_8c_a8d563c2c366a59b52ae25123a38c7603}{schc\_fragmenter\_init}}(\mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}* tx\_conn, }
\DoxyCodeLine{        \textcolor{keywordtype}{void} (*send)(uint8\_t* data, uint16\_t \mbox{\hyperlink{structschc__rule_af5f20076e164f0bbeaf3f2fbbab1ee78}{length}}, uint32\_t device\_id),}
\DoxyCodeLine{        \textcolor{keywordtype}{void} (*end\_rx)(\mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}* conn),}
\DoxyCodeLine{        \textcolor{keywordtype}{void} (*remove\_timer\_entry)(uint32\_t device\_id))}
\end{DoxyCode}
 The initilization function takes the following arguments\+:
\begin{DoxyItemize}
\item {\ttfamily tx\+\_\+conn}, which can be an empty {\ttfamily \mbox{\hyperlink{structschc__fragmentation__t}{schc\+\_\+fragmentation\+\_\+t}}} struct, to hold the information of the sending device.
\item {\ttfamily send} requires a pointer to a callback function, which will transmit the fragment over any interface and requires a platform specific implementation
\item {\ttfamily end\+\_\+rx} is called once the complete packet has been received (more information bellow)
\item {\ttfamily remove\+\_\+timer\+\_\+entry} had to be added for some platforms to remove timers once the complete transmission has been completed
\end{DoxyItemize}\hypertarget{md_README_autotoc_md8}{}\doxysubsubsection{mbuf}\label{md_README_autotoc_md8}
The fragmenter is built around the {\ttfamily mbuf} principle, derived from the B\+SD OS, where every fragment is part of a linked list. The fragmenter holds a preallocated number of slots, defined in {\ttfamily \mbox{\hyperlink{schc__config_8h}{schc\+\_\+config.\+h}}} with {\ttfamily \#define S\+C\+H\+C\+\_\+\+C\+O\+N\+F\+\_\+\+R\+X\+\_\+\+C\+O\+N\+NS}. Every received packet is added to the {\ttfamily M\+B\+U\+F\+\_\+\+P\+O\+OL}, containing a linked list of fragments for a particular connection. Once a transmission has been ended, the fragmenter will then glue together the different fragments.\hypertarget{md_README_autotoc_md9}{}\doxysubsubsection{Reassembly}\label{md_README_autotoc_md9}
Upon reception of a fragment, the following function should be called\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{\mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}* \mbox{\hyperlink{fragmenter_8c_a0fac20e73f52464091a717bde243deb3}{schc\_input}}(uint8\_t* data, uint16\_t len, \mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}* tx\_conn, uint32\_t device\_id)}
\end{DoxyCode}

\begin{DoxyItemize}
\item the {\ttfamily tx\+\_\+conn} structure is used to check if the received frame was an acknowledgment and will return the {\ttfamily tx\+\_\+conn} if so
\item the {\ttfamily device\+\_\+id} is used to find out if the current device is involved in an ongoing transmission and will return the {\ttfamily rx\+\_\+conn} if so
\end{DoxyItemize}

These return values can be used in the application to perform corresponding actions, e.\+g\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{uint8\_t ret = 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordflow}{if} (conn != \&tx\_conn) \{}
\DoxyCodeLine{    conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_ab0679bb4a377f6ce9da82769cf88c52c}{mode}} = \mbox{\hyperlink{fragmenter_8h_a00b61f9b90ab7065eb6a978141d7fd34a0344f277cbdd16e3f0ea0ff1d1be1b17}{NO\_ACK}};\textcolor{comment}{// todo get from rule}}
\DoxyCodeLine{    \textcolor{keywordflow}{if}(conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_ab0679bb4a377f6ce9da82769cf88c52c}{mode}} == \mbox{\hyperlink{fragmenter_8h_a00b61f9b90ab7065eb6a978141d7fd34a0344f277cbdd16e3f0ea0ff1d1be1b17}{NO\_ACK}}) \{ \textcolor{comment}{// todo get from rule}}
\DoxyCodeLine{        conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_af72b38948d4bb6fbc0a261cd092ddd10}{FCN\_SIZE}} = 1;}
\DoxyCodeLine{        conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_a5233caff42cce7f50dd5279b9d838400}{WINDOW\_SIZE}} = 0;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{    conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_af54664c2e4cfb10cc250896f070f6d5b}{post\_timer\_task}} = \&set\_rx\_timer;}
\DoxyCodeLine{    conn-\/>\mbox{\hyperlink{structschc__fragmentation__t_ac3fbcae2ee4198df9d04438d63d97361}{dc}} = 50000; \textcolor{comment}{// duty cycle}}
\DoxyCodeLine{    ret = \mbox{\hyperlink{fragmenter_8c_a6a248f74b7a8b0ef5f7dbc3f418e05a8}{schc\_reassemble}}(conn);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordflow}{if}(ret == 1) \{ \textcolor{comment}{// reception finished}}
\DoxyCodeLine{    packet\_to\_ip6(conn);}
\DoxyCodeLine{\}}
\end{DoxyCode}
 The above example is application code of the server, receiving a compressed, fragmented packet. By calling {\ttfamily schc\+\_\+reassemble}, the fragmenter will take care of adding fragments to the {\ttfamily M\+B\+U\+F\+\_\+\+P\+O\+OL}.

Once the reception is finished, {\ttfamily packet\+\_\+to\+\_\+ip6} is called, where the {\ttfamily mbuf} can be reassembled to a regular packet. First we want to get the length of the packet\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{uint16\_t \mbox{\hyperlink{fragmenter_8c_a974581b10381381bafe401fc2ddc54c7}{get\_mbuf\_len}}(\mbox{\hyperlink{structschc__mbuf__t}{schc\_mbuf\_t}} *head); \textcolor{comment}{// call with conn-\/>head as argument}}
\end{DoxyCode}
 Next, a buffer can be allocated with the appropriate length (the return value of {\ttfamily get\+\_\+mbuf\+\_\+len}). The reassmbled packet can then be copied to the pointer passed to the following function\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} \mbox{\hyperlink{fragmenter_8c_a3b3e7a45b2ff0f407adfcc266f47c3dc}{mbuf\_copy}}(\mbox{\hyperlink{structschc__mbuf__t}{schc\_mbuf\_t}} *head, uint8\_t* ptr); \textcolor{comment}{// call with conn-\/>head and pointer to allocated buffer}}
\end{DoxyCode}
 The result will be a compressed packet, which can be decompressed by using the decompressor.

Don\textquotesingle{}t forget to reset the connection. 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} \mbox{\hyperlink{fragmenter_8c_af04b125eaaa72e66f782bdb592133a27}{schc\_reset}}(\mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}* conn);}
\end{DoxyCode}
\hypertarget{md_README_autotoc_md10}{}\doxysubsubsection{Fragmentation}\label{md_README_autotoc_md10}
After compressing a packet, the return value of {\ttfamily schc\+\_\+compress} can be used to check whether a packet should be fragmented or not. In order to fragment a packet, the parameters of the connection should be set according to your preferences.


\begin{DoxyCode}{0}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_ab0679bb4a377f6ce9da82769cf88c52c}{mode}} = \mbox{\hyperlink{fragmenter_8h_a00b61f9b90ab7065eb6a978141d7fd34abb669910db44bb35ca22cfa0987cff5f}{ACK\_ON\_ERROR}};}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_aacb88301231fdf7ebf596250d3b75201}{mtu}} = current\_network\_driver-\/>mtu; \textcolor{comment}{// the maximum length of each fragment}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_ac3fbcae2ee4198df9d04438d63d97361}{dc}} = 20000; \textcolor{comment}{// duty cycle}}
\DoxyCodeLine{}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a54c6634755f3b9737e8c61d0fdea3a37}{data\_ptr}} = \&compressed\_packet; \textcolor{comment}{// the pointer to the compressed packet}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a81a06b0db6f570800959533e1fd2ce58}{packet\_len}} = err; \textcolor{comment}{// the total length of the packet}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a0d771b7ddff550f4e30b238f1a332572}{send}} = \&network\_driver\_send; \textcolor{comment}{// callback function to call for transmission}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_af72b38948d4bb6fbc0a261cd092ddd10}{FCN\_SIZE}} = 3; \textcolor{comment}{// todo get from rule}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_af8670ae896636ff443e1079940ba018c}{MAX\_WND\_FCN}} = 6; \textcolor{comment}{// todo will be removed?}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a5233caff42cce7f50dd5279b9d838400}{WINDOW\_SIZE}} = 1; \textcolor{comment}{// todo support multiple window sizes}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a815c8ccfa3da28a4140d60ff5e9e7b17}{DTAG\_SIZE}} = 0; \textcolor{comment}{// todo no support yet}}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_a8a6c636f8d863fc3db680da64ee889c1}{RULE\_SIZE}} = 8; \textcolor{comment}{// todo get from rule}}
\DoxyCodeLine{}
\DoxyCodeLine{tx\_conn.\mbox{\hyperlink{structschc__fragmentation__t_af54664c2e4cfb10cc250896f070f6d5b}{post\_timer\_task}} = \&set\_tx\_timer;}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{fragmenter_8c_a5c375e7b44652a0eccb9248083a6251d}{schc\_fragment}}((\mbox{\hyperlink{structschc__fragmentation__t}{schc\_fragmentation\_t}}*) \&tx\_conn); \textcolor{comment}{// start the fragmentation}}
\end{DoxyCode}
\hypertarget{md_README_autotoc_md11}{}\doxysubsubsection{Timers}\label{md_README_autotoc_md11}
As you can see in the above examples, the library has no native support for timers and requires callback functions from the main application to schedule transmissions and to time out. Therefore, 2 function callbacks are required. The following is based on the O\+S\+S-\/7 platform. 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{comment}{/*}}
\DoxyCodeLine{\textcolor{comment}{ * The timer used by the SCHC library to schedule the transmission of fragments}}
\DoxyCodeLine{\textcolor{comment}{ */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} set\_tx\_timer(\textcolor{keywordtype}{void} (*callback)(\textcolor{keywordtype}{void}* conn), uint32\_t device\_id, uint32\_t delay, \textcolor{keywordtype}{void} *arg) \{}
\DoxyCodeLine{    timer\_post\_task\_prio(callback, timer\_get\_counter\_value() + delay, DEFAULT\_PRIORITY, arg);}
\DoxyCodeLine{\}}
\end{DoxyCode}


As the server has to keep track of multiple devices and connections, a vector is used to keep track of multiple devices. The following is part of a C++ implementation, which makes use of the C library. 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{comment}{/*}}
\DoxyCodeLine{\textcolor{comment}{ * The timer used by the SCHC library to time out the reception of fragments}}
\DoxyCodeLine{\textcolor{comment}{ */}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} set\_rx\_timer(\textcolor{keywordtype}{void} (*callback)(\textcolor{keywordtype}{void}* conn), uint32\_t device\_id, uint32\_t delay, \textcolor{keywordtype}{void} *arg) \{}
\DoxyCodeLine{    add\_device(device\_id, delay, callback);}
\DoxyCodeLine{\}}
\end{DoxyCode}
\hypertarget{md_README_autotoc_md12}{}\doxysection{L\+I\+C\+E\+N\+SE}\label{md_README_autotoc_md12}
Licensed under the G\+NU General Public License, Version 3 (the \char`\"{}\+License\char`\"{})\+: You may not use these files except in compliance with the License. You may obtain a copy of the License at \href{https://www.gnu.org/licenses/gpl-3.0.nl.html}{\texttt{ https\+://www.\+gnu.\+org/licenses/gpl-\/3.\+0.\+nl.\+html}}

See the License for the specific language governing permissions and limitations under the License.

© Copyright 2018-\/2019, Bart Moons \href{mailto:bamoons.moons@ugent.be}{\texttt{ bamoons.\+moons@ugent.\+be}} and Ghent University 